import axios, { Axios } from "axios";
import { token } from "./user";
import { useStore } from 'vuex'


export const baseUrl = "http://localhost:8080/";

export async function fetchMovie(name) {
    const store = window.$store;
    console.log("in fetchMovie");
    console.log(baseUrl + `movie/search/${name}/${store.state.user.token}`);
    const respond = await axios.get(baseUrl + `movie/search/${name}/${store.state.user.token}`);
    console.log(respond);
    return respond.data.movies[0];
}

// 拉取电影类别
export async function fetchCatagories() {
    const store = window.$store;
    console.log(store.state.user.token);
    const respond = await axios.get(baseUrl + `movie/fetch/categories/${store.state.user.token}`);
    return respond.data;
}

//拉取所有电影
export async function fetchMovies() {
    const store = window.$store;
    console.log(store.state.user.token);
    const respond = await axios.get(baseUrl + `movie/fetch/${store.state.user.token}`);
    console.log(respond);
    return respond.data;
}

//按照类别筛选电影
export async function filterMovie(catagories) {
    const store = window.$store;
    const respond = await axios.get(baseUrl + `movie/class/${catagories}/${store.state.user.token}`);
    return respond.data;
}

export async function deleteComment(movieId) {
    const store = window.$store;
    const respond = await axios({
        method: 'post',
        url: baseUrl + `movieComment/delete`,
        params: {
            movieId,
            commentatorId:store.state.user.id,
            token:store.state.user.token
        }
    });

    
}

export async function commitComment(movieId,comment) {
    const store = window.$store;
    const respond = await axios({
        method: 'post',
        url: baseUrl + `movie/comment/${movieId}/${comment}/${store.state.user.id}/${store.state.user.token}`,
    });
}



